package com.example.recordingpen_datacollection.controller;

import com.example.recordingpen_datacollection.Utils.DateUtils.DateUtil;
import com.example.recordingpen_datacollection.redisService.RedisService;
import com.example.recordingpen_datacollection.result.RLIST;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/token")
public class TokenController {
    @Autowired
    private RedisService redisService;

    @ApiOperation(value = "刷新token")
    @GetMapping("/refresh")
    public RLIST test(HttpServletRequest request){
        String token = request.getHeader("token");
        redisService.setTokenValueDAYSReset(token,1);
        return RLIST.ok();
    }
    @ApiOperation(value = "查看token有效期token")
    @GetMapping("/test2")
    public RLIST test2(HttpServletRequest request){
        String token = request.getHeader("token");
        long tokenDate = redisService.getTokenDate(token);
        String s = DateUtil.stampToDate(tokenDate, "yyyy-MM-dd HH:mm:ss.SSS");
        System.out.println(s);
        return RLIST.ok().data("data",s);
    }


}
